package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.*;

import java.io.IOException;
import java.util.concurrent.*;

import static java.util.concurrent.TimeUnit.SECONDS;


public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        SynchronousQueue<Runnable> runnables = new SynchronousQueue<>();
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        //使用线程池不断调用
        ExecutorService ex = Executors.newFixedThreadPool(10);
        /*while (true) {
            System.in.read();
            try {
                String hello = service.sayHello("world", 0);
                System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }*/
        for(int i = 0;i< 1000;i++){
            Task task = new Task(service);
            ex.submit(task);
        }


    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {
    @Bean
    public RegistryConfig registryConfig() {
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress("zookeeper://127.0.0.1:2181?timeout=50000");
            return registryConfig;
        }
    }
}
